precision mediump float; // 中精度浮点数

varying vec2 vUV;

uniform sampler2D u_texture;

uniform vec4 u_color;

//ps叠加算法
float superposition( float a , float b ){
    float A = a * 255.;
    float B = b * 255.;
    float C;
    if ( A <= 128. ){
        C = A * B / 128.;
    }else{
        C = ( 255. - ( ( 255. - A ) * ( 255. - B ) ) / 128. );
    }
    return C / 255.;
}

//通用颜色混合算法
vec3 mixColorInPSComputer( vec3 underColor , vec3 upColor ){

    vec3 finalColor = vec3( 0. );

    finalColor.r = superposition( underColor.r , upColor.r );
    finalColor.g = superposition( underColor.g , upColor.g );
    finalColor.b = superposition( underColor.b , upColor.b );

    return finalColor;
}

void main( ){

    vec4 outPutColor = texture2D( u_texture , vUV );
    outPutColor.rgb = mixColorInPSComputer( outPutColor.rgb , u_color.rgb );

    gl_FragColor = vec4( outPutColor );
}
